

message = Map();
cfNme = "";
info cfNme;
fType = options.get("type");
shareChat = options.get("share");
shareLink = options.get("link");
memTyp = "";
if(arguments.get(0) != null)
{
	info "dg";
}
if(arguments.get(0) != null && fType == null && shareLink == null && shareChat == null)
{
	if(arguments.toLowerCase().contains("doc"))
	{
		arguSize = arguments.lastIndexOf(".doc");
		memTyp = "application/vnd.google-apps.document";
	}
	else if(arguments.toLowerCase().contains("sheet"))
	{
		arguSize = arguments.lastIndexOf(".sheet");
		memTyp = "application/vnd.google-apps.spreadsheet";
	}
	else if(arguments.toLowerCase().contains("slide"))
	{
		arguSize = arguments.lastIndexOf(".slide");
		memTyp = "application/vnd.google-apps.presentation";
	}
	else if(!arguments.toLowerCase().contains("doc") && !arguments.toLowerCase().contains("sheet") && !arguments.toLowerCase().contains("slide"))
	{
		memTyp = "application/vnd.google-apps.document";
		arguSize = arguments.length();
	}
	arguSubstr = arguments.subString(0,arguSize);
	cfNme = arguSubstr;
}
else
{
	if(arguments.get(0) == null)
	{
		cfNme = "Untitled";
	}
	else if(arguments.get(0) != null && fType == null)
	{
		share_check = arguments.get(0).contains("-share");
		link_check = arguments.get(0).contains("-link");
		if(share_check == true || link_check == true)
		{
			argu_real = arguments.get(0).toList("-").get(0);
			cfNme = argu_real.toList(".").get(0);
			real_name = argu_real.toList(".");
			real_name_len = real_name.size();
			info real_name_len;
			if(real_name_len == 1)
			{
				memTyp = "application/vnd.google-apps.document";
			}
			else if(real_name_len == 2)
			{
				type_here = argu_real.toList(".").get(1);
				info type_here;
				if(type_here == "doc ")
				{
					memTyp = "application/vnd.google-apps.document";
				}
				else if(type_here == "sheet ")
				{
					memTyp = "application/vnd.google-apps.spreadsheet";
				}
				else if(type_here == "slide ")
				{
					memTyp = "application/vnd.google-apps.presentation";
				}
			}
		}
	}
	else if(arguments.get(0) != null && fType != null)
	{
		info arguments.get(0);
		share_check = arguments.get(0).contains("-share");
		link_check = arguments.get(0).contains("-link");
		if(share_check == true || link_check == true)
		{
			info fType + "g";
			cfNme = arguments.get(0).toList("-").get(0);
			if(fType == "doc")
			{
				memTyp = "application/vnd.google-apps.document";
			}
			else if(fType == "sheet")
			{
				memTyp = "application/vnd.google-apps.spreadsheet";
			}
			else if(fType == "slide")
			{
				memTyp = "application/vnd.google-apps.presentation";
			}
		}
		else
		{
			cfNme = arguments.get(0);
			if(fType == "doc")
			{
				memTyp = "application/vnd.google-apps.document";
			}
			else if(fType == "sheet")
			{
				info "st";
				memTyp = "application/vnd.google-apps.spreadsheet";
			}
			else if(fType == "slide")
			{
				memTyp = "application/vnd.google-apps.presentation";
			}
		}
	}
}
info memTyp;
setFileTypes = Map();
setFileTypes.put("title",cfNme);
setFileTypes.put("mimeType",memTyp);
headersMp = Map();
headersMp.put("Content-Type","application/json");
response = invokeurl
[
	url :"https://www.googleapis.com/drive/v2/files"
	type :POST
	parameters:setFileTypes.toString()
	headers:headersMp
	connection:"*INSERT_YOUR_CONNECTION_NAME*"
	useraccess:true
];
editLink = response.getJson("alternateLink");
file_Id = response.getJson("id");
thumLink = response.get("thumbnailLink");
file_name = response.get("title");
ownerName = response.get("owners").getJSON("displayName");
emailIdlist = List();
info thumLink;
if(shareChat == "")
{
	userCnt = chat.get("userscount");
	users = chat.get("users");
	info "----- " + users;
	for each  members in users
	{
		usersMap = members.toMap();
		emailId = usersMap.get("email");
		if(emailId != zoho.loginuserid)
		{
			emailIdlist.add(emailId);
		}
	}
	for each  emailId in emailIdlist
	{
		permissions = Map();
		permissions.put("role","writer");
		permissions.put("type","user");
		permissions.put("value",emailId);
		response = invokeurl
		[
			url :"https://www.googleapis.com/drive/v2/files/" + file_Id + "/permissions"
			type :POST
			parameters:permissions.toString()
			headers:headersMp
			connection:"*INSERT_YOUR_CONNECTION_NAME*"
			useraccess:true
		];
	}
}
else if(shareLink == "")
{
	info "Called";
	permissions = Map();
	permissions.put("withLink","true");
	permissions.put("role","writer");
	permissions.put("type","anyone");
	response = invokeurl
	[
		url :"https://www.googleapis.com/drive/v2/files/" + file_Id + "/permissions"
		type :POST
		parameters:permissions.toString()
		headers:headersMp
		connection:"*INSERT_YOUR_CONNECTION_NAME*"
		useraccess:true
	];
	info response;
}
anyoneLink = "https://drive.google.com/open?id=" + file_Id;
buttonObj = Map();
buttonObj.put("label","open");
if(shareLink == "" || shareChat == "")
{
	buttonObj.put("label","shared_link");
}
buttonObj.put("hint","Just click to open the file");
buttonObj.put("type","+");
clickObj = Map();
clickObj.put("type","open.url");
actionDataObj = Map();
if(shareLink == "")
{
	actionDataObj.put("web",anyoneLink);
}
else if(shareChat == "")
{
	actionDataObj.put("web",editLink);
}
else
{
	actionDataObj.put("web",editLink);
}
clickObj.put("data",actionDataObj);
buttonObj.put("action",clickObj);
buttonArray = List();
buttonArray.add(buttonObj);
if(memTyp.contains("document"))
{
	thumLink = "https://www.zoho.com/extensions/images/cliq/gdrive-document.png";
}
else if(memTyp.contains("sheet"))
{
	thumLink = "https://www.zoho.com/extensions/images/cliq/gdrive-sheet.png";
}
else if(memTyp.contains("presentation"))
{
	thumLink = "https://www.zoho.com/extensions/images/cliq/gdrive-slide.png";
}
msgMp = Map();
msgMp.put("title",file_name);
msgMp.put("thumbnail",thumLink);
msgMp.put("theme","7");
message.put("text","by " + ownerName);
message.put("card",msgMp);
message.put("buttons",buttonArray);
if(shareChat == "" || shareLink == "")
{
	info message;
	zoho.chat.postToChat(chat.get("id"),message);
}
else
{
	info message;
	return message;
}
return Map();
